home *** CD-ROM | disk | FTP | other *** search
/ PC Direct 1998 August / PC Direct August 1998.iso / S / powerj / Product / hpp.z / wmasktb.hpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-11-25  |  9.6 KB  |  300 lines

  1. #ifndef _WMASKTB_HPP_INCLUDED
  2. #define _WMASKTB_HPP_INCLUDED
  3.  
  4. /*************************************************************************
  5.  *
  6.  * WMaskedTextBox -- Base MaskedTextBox class
  7.  *
  8.  *
  9.  *   Events:
  10.  *
  11.  ************************************************************************/
  12.  
  13. enum WDateOrder {
  14.     WDateOrderUSA,
  15.     WDateOrderEUR,
  16.     WDateOrderJIS,
  17. };
  18.  
  19. #include <ctype.h>
  20. #ifndef _WTEXTBOX_HPP_INCLUDED
  21. #  include "wtextbox.hpp"
  22. #endif
  23.  
  24. #define DEFAULT_PROMPT_CHAR              '_'
  25. #define MASK_DIGIT                       '#'
  26. #define MASK_ALPHANUM                    '?'
  27. #define MASK_UPPERCASE                   'U'
  28. #define MASK_LOWERCASE                   'L'
  29. #define MASK_MIXEDCASE                   'M'
  30. #define MASK_DECIMAL_SEP                 '.'
  31. #define MASK_THOUSANDS_SEP               ','
  32. #define MASK_TIME_SEP                    ':'
  33. #define MASK_DATE_SEP                    '/'
  34. #define MASK_WILD                        '*'
  35. #define MASK_LITERAL                     '\\'
  36.  
  37. // Text formatting constants and data structures
  38.  
  39. #define VALID_ROUTINE                  0
  40. #define INVALID_ROUTINE                40
  41. #define MAXYEAR                        3000
  42.  
  43. enum {
  44.     DECIMAL_SUB = 0,
  45.     THOUSANDS_SUB,
  46.     TIMESEP_SUB,
  47.     DATESEP_SUB,
  48.     NUM_COUNTRY,
  49. };
  50.  
  51. typedef struct dateInf {
  52.     WULong   month;
  53.     WULong   year;
  54.     WULong   daynum;
  55.     WULong   day;
  56.     WBool    dayset;
  57.     WBool    daynumset;
  58.     WBool    yearset;
  59.     WBool    monthset;
  60. } dateInfo;
  61.  
  62. typedef dateInfo * pdateInfo;
  63.  
  64. typedef struct timeInf {
  65.     WULong   hours;
  66.     WULong   minutes;
  67.     WULong   seconds;
  68.     WULong   millths;
  69.     WBool    millthsset;
  70.     WBool    secondsset;
  71.     WBool    minutesset;
  72.     WBool    hoursset;
  73. } timeInfo;
  74.  
  75. typedef timeInfo * ptimeInfo;
  76.  
  77. typedef struct numInf {
  78.     WString      number;
  79.     WLong        exponent;
  80.     WBool        negative;
  81. } numInfo;
  82.  
  83. typedef numInfo * pnumInfo;
  84.  
  85.  
  86. class WCMCLASS WMaskedTextBox : public WTextBox
  87. {
  88.     WDeclareSubclass( WMaskedTextBox, WTextBox );
  89.  
  90.     /**************************************************************
  91.      * Constructors and destructors
  92.      **************************************************************/
  93.  
  94.     public:
  95.  
  96.         WMaskedTextBox();
  97.  
  98.         ~WMaskedTextBox();
  99.  
  100.     public:
  101.  
  102.     /**************************************************************
  103.      * Properties
  104.      **************************************************************/
  105.  
  106.         // AcceptLiterals
  107.  
  108.         WBool GetAcceptLiterals() const;
  109.         WBool SetAcceptLiterals( WBool acceptLiterals );
  110.  
  111.         // Autotab
  112.  
  113.         WBool GetAutoTab() const;
  114.         WBool SetAutoTab( WBool val );
  115.  
  116.         // BeepOnInvalidInput
  117.  
  118.         WBool GetBeepOnInvalidInput() const;
  119.         WBool SetBeepOnInvalidInput( WBool beepOnInvalidInput );
  120.  
  121.         // DateOrder
  122.         
  123.         WDateOrder GetDateOrder() const;
  124.         WBool      SetDateOrder( WDateOrder order );
  125.  
  126.         // FormattedText
  127.         
  128.         WString GetFormattedText() const;
  129.  
  130.         // InputMask
  131.         
  132.         WString GetInputMask() const;
  133.         WBool   SetInputMask( WString mask );
  134.  
  135.         // MaskedText
  136.  
  137.         WString GetMaskedText() const;
  138.  
  139.         // OutputFormat
  140.         
  141.         WString GetOutputFormat() const;
  142.         WBool   SetOutputFormat( WString format );
  143.  
  144.         // PromptChar
  145.         
  146.         WChar GetPromptChar() const;
  147.         WBool SetPromptChar( WChar newchar );
  148.  
  149.         // UseCurrentDate
  150.  
  151.         WBool GetUseCurrentDate() const;
  152.         WBool SetUseCurrentDate( WBool val );
  153.  
  154.         // UsePeriodDateFormat
  155.  
  156.         WBool GetUsePeriodDateFormat() const;
  157.         WBool SetUsePeriodDateFormat( WBool val );
  158.  
  159.  
  160.         WRange GetEditSelectionWithDBCS() const;
  161.         WBool SetEditSelectionWithDBCS( WRange & editSelection );
  162.     /**************************************************************
  163.      * Methods
  164.      **************************************************************/
  165.  
  166.     public:
  167.         static WString FormatString( WString input, WString mask,
  168.                                      WBool useCurDate = FALSE,
  169.                                      WBool usePerDateFormat = FALSE,
  170.                                      WDateOrder dOrder = WDateOrderUSA,
  171.                                      WBool stripPromptChars = TRUE,
  172.                                      WChar promptChar = DEFAULT_PROMPT_CHAR );
  173.  
  174.     /**************************************************************
  175.      * Event Handlers
  176.      **************************************************************/
  177.  
  178.     public:
  179.         
  180.         WBool CreateEventHandler( WWindow *, WCreateEventData * );
  181.         WBool LostFocusHandler( WWindow *, WFocusEventData * );
  182.         WBool GotFocusHandler( WWindow *, WFocusEventData * );
  183.         WBool ChangeEventHandler( WWindow *, WEventData * );
  184.         WBool DataAvailableHandler( WMaskedTextBox *, WDataAvailableEventData *ev );
  185.         WBool DataRequestHandler( WMaskedTextBox *, WDataRequestEventData *ev );
  186.  
  187.     /**************************************************************
  188.      * Overriddes
  189.      **************************************************************/
  190.  
  191.     public:
  192.         WBool   ProcessMessage( const WMessage &msg, WLong &returns );
  193.         virtual WBool SetText( const WString &text );
  194.         WString GetText( WULong line ) const;
  195.         virtual WString GetText() const;
  196.         virtual WBool CloneWindow( WStyle newStyle, WStyle newExStyle,
  197.                                    void *data );
  198.         virtual WBool LoadWindow( WWindow * parent,
  199.                                   const WResourceID & id,
  200.                                   WModuleHandle module=_ApplicationModule );
  201.         virtual WBool MakeWindow( WWindow * parent, WUInt id,
  202.                                   const WChar *className,
  203.                                   const WChar *title, const WRect & r,
  204.                                   WStyle wstyle, WStyle exStyle,
  205.                                   void * data=NULL );
  206.     
  207.     /**************************************************************
  208.      * Others
  209.      **************************************************************/
  210.  
  211.     protected:
  212.  
  213.         WBool  AllocDTCell();
  214.         WRange FilterAndInsert( WRange selected, WString text );
  215.         WBool  ProcessKeyPress( WInt key );
  216.         WBool  ProcessCharacter( WInt pos, WInt key );
  217.         void   SetNewPromptStr( WString mask );
  218.         WInt   GetNumLiterals( WRange selRange ) const;
  219.         void   CheckAutoTab() const;
  220.         void   PasteText();
  221.  
  222.  
  223.     /**************************************************************
  224.      * Text formatting functions
  225.      **************************************************************/
  226.  
  227.     protected:
  228.  
  229.         static WString Format( WString input, WString mask,
  230.                               WBool usecurrentdate,
  231.                               WBool usePerDateFormat, WULong inptype );
  232.  
  233.         static WBool GetEraYear( WULong year, WString &sEra, WULong &lYear );
  234.  
  235.         static WULong DaysThisYear( WULong year, WULong month,
  236.                                     WULong daynum );
  237.  
  238.         static void InvBaseDate( WULong daynumber, pdateInfo dinfo );
  239.  
  240.         static WULong BaseDate( WULong year, WULong month, WULong daynum );
  241.  
  242.         static WBool DayCheck( pdateInfo dinfo );
  243.  
  244.         static WBool FormatInDateInfo( pdateInfo dinfo, WString input,
  245.                                        WBool usecurrentdate,
  246.                                        WULong inptype );
  247.  
  248.         static WString FormatOutDateInfo( pdateInfo dinfo, WString mask,
  249.                                           WBool usePerDateFormat );
  250.  
  251.         static WString FormatDate( WString input, WString mask,
  252.                                   WBool usecurrentdate,
  253.                                   WBool usePerDateFormat, WULong inptype );
  254.  
  255.         static WBool FormatInTimeInfo( ptimeInfo tinfo,
  256.                                        WString input, WBool usecurrentdate );
  257.  
  258.         static WString FormatOutTimeInfo( ptimeInfo tinfo,
  259.                                           WString mask );
  260.  
  261.         static WString FormatTime( WString input, WString mask,
  262.                                    WBool usecurrentdate );
  263.  
  264.         static WBool FormatInNumberInfo( pnumInfo ninfo, WString input );
  265.  
  266.         static WULong FormatOutNumber( WString &output, WString mask,
  267.                                        pnumInfo ninfo );
  268.  
  269.         static WString FormatOutNumberInfo( pnumInfo ninfo, WString mask );
  270.  
  271.         static WString FormatNumber( WString input, WString mask );
  272.  
  273.         static WString FormatOutString( WString input, WString mask );
  274.  
  275.     /**************************************************************
  276.      * Data Members
  277.      **************************************************************/
  278.  
  279.     protected:
  280.  
  281.         WString                    _inputMask;
  282.         WString                    _outputFormat;
  283.         WString                    _promptStr;
  284.         WString                    _rawText;
  285.         WString                    _maskNoLiterals;
  286.         WChar                      _promptChar;
  287.         WInt                       _maskLen;
  288.         WBool                      _useCurDate;
  289.         WBool                      _autoTab;
  290.         WBool                      _usePDateFormat;
  291.         WBool                      _restore;
  292.         WDateOrder                 _dateOrder;
  293.         char                      *_literalPos;    
  294.         WBool                      _faked;
  295.         WBool                      _acceptLiterals;
  296.         WBool                      _beepOnInvalidInput;
  297. };
  298.  
  299. #endif
  300.